package com.yxch.admin.service.impl.video;

import com.yxch.admin.mapper.video.VideoMapper;
import com.yxch.admin.model.commen.PageResult;
import com.yxch.admin.model.video.VideoDTO;
import com.yxch.admin.model.video.VideoVO;
import com.yxch.admin.service.video.VideoService;
import com.yxch.admin.utils.ResultAPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VideoServiceImpl implements VideoService {
    private static final Logger log = LoggerFactory.getLogger(VideoServiceImpl.class);
    @Autowired
    VideoMapper videoMapper;

    @Override
    public ResultAPI getVideoList(VideoDTO videoDTO) {
        //获取数据
        Integer page = videoDTO.getPageNum();
        Integer pageSize = videoDTO.getPageSize();
        Integer startIndex = (page - 1) * pageSize;

        videoDTO.setStart(startIndex);
        List<VideoVO> videoVOS = videoMapper.getVideoList(videoDTO);
        //获取总和
        Integer total = videoMapper.getVideoListCount(videoDTO);

        PageResult result = new PageResult();
        result.setTotal(total);
        result.setItems(videoVOS);
        return ResultAPI.success(result);
    }

    @Override
    public ResultAPI getVideoById(Integer resource_id) {
        VideoVO videoVO = videoMapper.getVideoById(resource_id);
        log.info(videoVO.toString());
        return ResultAPI.success(videoVO);
    }

    @Override
    public ResultAPI updateVideo(VideoVO videoVO) {
        videoMapper.updateVideo(videoVO);
        return ResultAPI.success();
    }
}
